// 定义程序

App = {
  version : '1.0.0',
  versionDetail : {
    major : 1,
    minor : 0,
    patch : 0
  },
  // 打印控件
  loopname : "江苏鑫亿软件有限公司",
  loopno : "059717168848673851905623562384",
  // 简单连接样式
  alinkStyle : "<STYLE>a { color:#0000FF;text-decoration:underline;}"
      + "a:visited { color:#CC0000; text-decoration:underline; }"
      + "a:hover { color:#CC0000; text-decoration:none; }"
      + "a:active { color:#CC00CC;text-decoration:underline; }" + "</STYLE>",

  btnPrevImage : 'resources/img/fam.icons/left.gif',
  btnNextImage : 'resources/img/fam.icons/right.gif',
  orgFloor : 2,
  resourceFloor : 2
};

// 分页
App.defaultPage = (function() {
  var page = 20;
  Ext.Ajax.request({
        url : "common/get_default_page",
        method : 'POST',
        async : false,

        callback : function(o, s, r) {
          var resp = Ext.decode(r.responseText);
          if (resp.success) {
            page = parseInt(resp.data);
          }
        }
      });

  return page;
}());

// 弹出窗口的尺寸
WindowSize = {
  height : 500,
  width : 700,
  widthScala : 0.90,
  heightScala : 0.85
};

Ext.BLANK_IMAGE_URL = 'resources/img/s.gif';
Ext.QuickTips.init();
// Ext.Ajax.timeout = 300000;//12000s,90000;

// 解决ExtJs TextField maxLength后还是可以输入
Ext.form.TextField.prototype.size = 20;
Ext.form.TextField.prototype.initValue = function() {
  if (this.value !== undefined) {
    this.setValue(this.value);
  } else if (this.el.dom.value.length > 0) {
    this.setValue(this.el.dom.value);
  }
  this.el.dom.size = this.size;
  if (!isNaN(this.maxLength) && (this.maxLength * 1) > 0
      && (this.maxLength != Number.MAX_VALUE)) {
    this.el.dom.maxLength = this.maxLength * 1;
  }
};

// Ext grid 超级强大的动态添加字段、列扩展
// grid.addColumn('C'); //添加C列，空数据
// grid.addColumn({name: 'D', defaultValue: 'D'}, {header: 'D', dataIndex:
// 'D'});//添加D列，有D数据
// grid.removeColumn('B');//把之前的B列删除
Ext.override(Ext.data.Store, {
      addField : function(field) {
        field = new Ext.data.Field(field);
        this.recordType.prototype.fields.replace(field);
        if (typeof field.defaultValue != 'undefined') {
          this.each(function(r) {
                if (typeof r.data[field.name] == 'undefined') {
                  r.data[field.name] = field.defaultValue;
                }
              });
        }
      },
      removeField : function(name) {
        this.recordType.prototype.fields.removeKey(name);
        this.each(function(r) {
              delete r.data[name];
              if (r.modified) {
                delete r.modified[name];
              }
            });
      }
    });
Ext.override(Ext.grid.ColumnModel, {
      addColumn : function(column, colIndex) {
        if (typeof column == 'string') {
          column = {
            header : column,
            dataIndex : column
          };
        }
        var config = this.config;
        this.config = [];
        if (typeof colIndex == 'number') {
          config.splice(colIndex, 0, column);
        } else {
          colIndex = config.push(column);
        }
        this.setConfig(config);
        return colIndex;
      },
      removeColumn : function(colIndex) {
        var config = this.config;
        this.config = [config[colIndex]];
        config.splice(colIndex, 1);
        this.setConfig(config);
      }
    });
Ext.override(Ext.grid.GridPanel, {
      // 不增加field
      addColumnNoField : function(field, column, colIndex) {
        if (!column) {
          if (field.dataIndex) {
            column = field;
            field = field.dataIndex;
          } else {
            column = field.name || field;
          }
        }
        // 取消，会影响记录显示
        // this.store.addField(field);
        return this.colModel.addColumn(column, colIndex);
      },
      addColumn : function(field, column, colIndex) {
        if (!column) {
          if (field.dataIndex) {
            column = field;
            field = field.dataIndex;
          } else {
            column = field.name || field;
          }
        }
        this.store.addField(field);
        return this.colModel.addColumn(column, colIndex);
      },
      removeColumn : function(name, colIndex) {
        this.store.removeField(name);
        if (typeof colIndex != 'number') {
          colIndex = this.colModel.findColumnIndex(name);
        }
        if (colIndex >= 0) {
          this.colModel.removeColumn(colIndex);
        }
      }
    });

Ext.namespace('Divo');
Ext.namespace('Divo.Com');
Ext.ns('Divo.com');

Divo.com.LOOP_EM = '<div id="LodopDiv"><object id="LODOP" '
    + 'classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>'
    + '<embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0 '
    + 'pluginspage="install_lodop.exe"></embed></object></div>'

Divo.com.Lib = function() {
  var t1 = '<tpl for=\".\">';
  var t2 = '</tpl>';
  /** *************** private method ******************* */

  /**
   * 返回ds,支付方式
   */
  function getPayTypeDs() {
    var recordDef = Ext.data.Record.create([{
          name : "typeCode",
          type : "string"
        }, {
          name : "typeName",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'paytype/query'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'typeCode'
              }, recordDef)
        });

    return ds;

  }

  /**
   * 返回tpl,支付方式
   */
  function getPayTypeTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{typeName}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  /**
   * 返回ds,合同类别
   */
  function getContractTypeDs() {
    var recordDef = Ext.data.Record.create([{
          name : "typeCode",
          type : "string"
        }, {
          name : "type",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'contract/query_type'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'typeCode'
              }, recordDef)
        });

    return ds;

  }

  /**
   * 返回tpl,合同类别
   */
  function getContractTypeTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{type}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  /**
   * 返回ds,所有企业
   */
  function getCompanyDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'company/query'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;

  }

  /**
   * 返回tpl,所有企业
   */
  function getCompanyTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{name}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }
  function getPayerDs() {
    var recordDef = Ext.data.Record.create([{
          name : "payerId",
          type : "float"
        }, {
          name : "payer",
          type : "string"
        }]);
    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'process/queryPayer'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'payerId'
              }, recordDef)
        });
    return ds;
  }
  function getPayerTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{payer}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }
  /**
   * 返回ds,银行
   */
  function getBankDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }, {
          name : "bankName",
          type : "string"
        }, {
          name : "bankType",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'bank/query'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;

  }

  function getAccountDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }, {
          name : "bankName",
          type : "string"
        }, {
          name : "bankType",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'account/query_account'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;

  }
  function getBankByContract(entId, logiId) {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }, {
          name : "bankName",
          type : "string"
        }, {
          name : "bankType",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          baseParams : {
            entId : entId,
            logiId : logiId
          },
          proxy : new Ext.data.HttpProxy({
                url : 'bank/query_bank_contract'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;
  }

  /**
   * 返回tpl,银行
   */
  function getBankTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{bankName}</b>-<b>{name}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  function getAccountTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{bankName}</b>-<b>{name}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }
  /**
   * 返回ds,物流中心
   */
  function getLogisticsDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'logistics/query'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;

  }

  /**
   * 返回tpl,物流中心
   */
  function getLogisticsTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{name}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }
  /**
   * 返回ds,账期、结算日
   */
  function getPeriodPayDate() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "enterpriseId",
          type : "string"
        }, {
          name : "enterprise",
          type : "string"
        }, {
          name : "period",
          type : "string"
        }, {
          name : "payDate",
          type : "string"
        }]);
    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'contract/query_periodpaydate'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    return ds;
  }
  /**
   * 返回ds,企业
   */
  function getEnterpriseDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'enterprise/query'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;

  }
  /**
   * 返回ds,企业
   */
  function getEnterpriseContractDs(type) {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          baseParams : {
            type : type
          },
          proxy : new Ext.data.HttpProxy({
                url : 'enterprise/query_diff'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;

  }

  /**
   * 返回tpl,企业
   */
  function getEnterpriseTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{name}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  function getBuyerDs() {
    var recordDef = Ext.data.Record.create([{
          name : "supplierId",
          type : "float"
        }, {
          name : "supplier",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'enterprise/query_buyer'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'supplierId'
              }, recordDef)
        });

    return ds;

  }

  /**
   * 返回tpl,企业
   */
  function getBuyerTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{supplier}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  function getSellerDs() {
    var recordDef = Ext.data.Record.create([{
          name : "enterpriseId",
          type : "float"
        }, {
          name : "enterprise",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'enterprise/query_sellers'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'enterpriseId'
              }, recordDef)
        });

    return ds;

  }

  function getStockDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'stock/query_stock_enable'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;

  }

  function getActionTypeDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'action_type/query_enable'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });

    return ds;

  }

  /**
   * 返回tpl,企业
   */
  function getSellerTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{enterprise}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  /**
   * 返回ds,买卖合同性质
   */
  function getBContractPropertyDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.MemoryProxy([[1, '订单融资借款'], [2, '未来提货权借款(买卖型)'],
              [3, '未来提货权借款(代理型)']]),
          reader : new Ext.data.ArrayReader({}, recordDef)
        });

    return ds;

  }

  /**
   * 返回tpl,买卖合同性质
   */
  function getBContractPropertyTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{name}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }
  /**
   * 返回ds,贷款性质
   */
  function getLoanNatureDs(companyId) {
    var recordDef = Ext.data.Record.create([{
          name : "loanNatureId",
          type : "string"
        }, {
          name : "loanNature",
          type : "string"
        }]);
    var ds = new Ext.data.Store({
          baseParams : {
            companyId : companyId
          },
          proxy : new Ext.data.HttpProxy({
                url : 'loan/query_nature'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'loanNatureId'
              }, recordDef)
        });
    return ds;

  }

  /**
   * 返回tpl,贷款性质
   */
  function getLoanNatureTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{loanNature}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }
  /**
   * 返回ds,所属银行种类
   */
  function getBankTypeDs() {
    var recordDef = Ext.data.Record.create([{
          name : "bankType",
          type : "string"
        }, {
          name : "bankName",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          baseParams : {
            'isBank' : '1'
          },
          proxy : new Ext.data.HttpProxy({
                url : 'bankkind/query'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'bankType'
              }, recordDef)
        });

    return ds;

  }

  function getSupplierBlackDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "string"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'supplier/query_blacklist'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    return ds;

  }

  function getAccountTypeDs() {
    var recordDef = Ext.data.Record.create([{
          name : "code",
          type : "string"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'account_type/query_enable'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'code'
              }, recordDef)
        });
    return ds;

  }

  function getTofficesDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "string"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'toffices/query'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    return ds;

  }

  function getSupplierEnableDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "string"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'supplier/query_enable'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    return ds;

  }

  function getUsersDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "string"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'system/get_users'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    return ds;

  }

  function getMaterialDs() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "string"
        }, {
          name : "name",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'high_value_material/query_d'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    return ds;

  }

  /**
   * 返回tpl,所属银行种类
   */
  function getBankTypeTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{bankName}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  /**
   * 返回ds,物品种类
   */
  function getGoodsCodeDs(flg) {
    var recordDef = Ext.data.Record.create([{
          name : "code",
          type : "string"
        }, {
          name : "name",
          type : "string"
        }, {
          name : "spec",
          type : "string"
        }, {
          name : "price",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          baseParams : {
            flg : flg
          },
          proxy : new Ext.data.HttpProxy({
                url : 'stork_company/query_code'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'code'
              }, recordDef)
        });
    return ds;

  }

  /**
   * 返回tpl,物品种类
   */
  function getGoodsCodeTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{name}({spec})</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  // 导入采集归集状态描述说明
  function getRunStatusTbr() {
    var msgbar = new Ext.Toolbar({
          items : [{
                xtype : 'tbtext',
                text : '成功'
              }, {
                xtype : 'box',
                autoEl : {
                  tag : 'img',
                  src : 'resources/img/su1.gif'
                }
              }, '-', {
                xtype : 'tbtext',
                text : '失败'
              }, {
                xtype : 'box',
                autoEl : {
                  tag : 'img',
                  src : 'resources/img/su2.gif'
                }
              }, '-', {
                xtype : 'tbtext',
                text : '验证失败'
              }, {
                xtype : 'box',
                autoEl : {
                  tag : 'img',
                  src : 'resources/img/su4.gif'
                }
              }, '-', {
                xtype : 'tbtext',
                text : '被终止'
              }, {
                xtype : 'box',
                autoEl : {
                  tag : 'img',
                  src : 'resources/img/su9.gif'
                }
              }, '-', {
                xtype : 'tbtext',
                text : '运行'
              }, {
                xtype : 'box',
                autoEl : {
                  tag : 'img',
                  src : 'resources/img/su3.gif'
                }
              }, '-', {
                xtype : 'tbtext',
                text : '等待'
              }, {
                xtype : 'box',
                autoEl : {
                  tag : 'img',
                  src : 'resources/img/su0.gif'
                }
              }

          ]
        });

    return msgbar;
  }

  //
  function getRunLogViewSel() {
    var ds = new Ext.data.SimpleStore({
          fields : ['value', 'name'],
          data : [[0, '全部'], [1, '物流宝'], [2, '银行'], [3, '物流公司'], [4, '企业']]
        })
    return ds;
  }
  function getSelect() {
    var ds = new Ext.data.SimpleStore({
          fields : ['value', 'name'],
          data : [[0, '自充'], [1, '代充']]
        })
    return ds;
  }
  function getPrecent() {
    var ds = new Ext.data.SimpleStore({
          fields : ['value', 'name'],
          data : [[0, '0%'], [10, '10%'], [20, '20%'], [30, '30%'],
              [40, '40%'], [50, '50%'], [60, '60%'], [70, '70%'], [80, '80%'],
              [90, '90%'], [100, '100%']]
        })
    return ds;
  }

  // 24
  function getHours() {

    var recordDef = Ext.data.Record.create([{
          name : "name",
          type : "string"
        }, {
          name : "value",
          type : "string"
        }]);

    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'common/get_hours'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'name'
              }, recordDef)
        });

    return ds;
  }

  function getHoursLocal() {
    var da = [];
    var o = []
    // 0-23
    for (var i = 0; i < 24; i++) {
      o = [i, i + "时"]
      da.push(o);
    }
    var comboStore = new Ext.data.ArrayStore({
          fields : ['value', 'name'],
          data : da
        });
    return comboStore;
  }

  // 60
  function getMins() {
    var recordDef = Ext.data.Record.create([{
          name : "name",
          type : "string"
        }, {
          name : "value",
          type : "string"
        }]);
    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'common/get_mins'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'name'
              }, recordDef)
        });

    return ds;

  }

  function getHighValueType() {
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float"
        }, {
          name : "name",
          type : "string"
        }]);
    var storeDs = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'high_value_material/query_s'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    return storeDs;
  }

  function getMinsLocal() {
    var da = [];
    var o = []
    // 0- 59
    for (var i = 0; i < 60; i++) {
      o = [i, i + "分"]
      da.push(o);
    }
    var comboStore = new Ext.data.ArrayStore({
          fields : ['value', 'name'],
          data : da
        });
    return comboStore;

  }

  // 界面显示用，取参数设置中导入前几天的数据
  function getAutoRunBefDays() {
    var recordDef = Ext.data.Record.create([{
          name : "name",
          type : "string"
        }, {
          name : "value",
          type : "string"
        }]);
    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'cron/get_autorun_bef_days'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'name'
              }, recordDef)
        });
    return ds;
  }

  function getExceptionDs() {
    var recordDef = Ext.data.Record.create([{
          name : "name",
          type : "string"
        }, {
          name : "id",
          type : "float"
        }]);
    var ds = new Ext.data.Store({
          proxy : new Ext.data.HttpProxy({
                url : 'exception_query/query_exception'
              }),
          reader : new Ext.data.JsonReader({
                root : 'rows',
                totalProperty : 'totalCount',
                id : 'id'
              }, recordDef)
        });
    ds.load();
    return ds;
  }

  function getExceptionTpl() {

    var resultTpl = [t1 + '<div class="x-combo-list-item">',
        '<b>{name}</b><br>', '</div>' + t2].join('');

    return resultTpl;

  }

  /**
   * Custom function used for column renderer
   * 
   * @param {Object}
   *          val
   */
  function changeRowColor(val) {
    if (val > 0) {
      return '<span style="color:green;">' + val + '</span>';
    } else if (val < 0) {
      return '<span style="color:red;">' + val + '</span>';
    }
    return val;
  }

  /**
   * Custom function used for column renderer
   * 
   * @param {Object}
   *          val
   */
  function pctChangeRowColor(val) {
    if (val > 0) {
      return '<span style="color:green;">' + val + '%</span>';
    } else if (val < 0) {
      return '<span style="color:red;">' + val + '%</span>';
    }
    return val;
  }

  // 取全部的系统变量
  function defaultValues() {
    var results = []
    Ext.Ajax.request({
          url : "appsetup/all_setupinfo",
          method : 'POST',
          async : false,

          callback : function(o, s, r) {
            var resp = Ext.decode(r.responseText);
            if (resp.success) {
              results = resp.data;
            }
          }
        });

    return results;
  }

  // 静态下拉框
  function getStaticDateDs(data) {
    var proxy = new Ext.data.MemoryProxy(data);
    var recordDef = Ext.data.Record.create([{
          name : "id",
          type : "float",
          mapping : 0
        }, {
          name : "name",
          type : "string",
          mapping : 1
        }]);
    var ds = new Ext.data.Store({
          proxy : proxy,
          reader : new Ext.data.JsonReader({}, recordDef),
          autoLoad : true
        });
    return ds;
  }

  function getWindowHeight() {
    var height = document.body.clientHeight * WindowSize.heightScala;
    return height;
  }

  function getWindowWidth() {
    var width = document.body.clientWidth * WindowSize.widthScala;
    return width;
  }
  /** *********** public method ************ */
  return {
    /**
     * 初始化工具类函数
     */
    init : function() {

    },
    getPayTypeDs : function() {
      return getPayTypeDs();
    },
    getPayTypeTpl : function() {
      return getPayTypeTpl();
    },
    getContractTypeDs : function() {
      return getContractTypeDs();
    },
    getContractTypeTpl : function() {
      return getContractTypeTpl();
    },
    getPayerDs : function() {
      return getPayerDs();
    },
    getPayerTpl : function() {
      return getPayerTpl();
    },
    getCompanyDs : function() {
      return getCompanyDs();
    },
    getCompanyTpl : function() {
      return getCompanyTpl();
    },
    getBankDs : function() {
      return getBankDs();
    },
    getAccountDs : function() {
      return getAccountDs();
    },
    getAccountTpl : function() {
      return getAccountTpl();
    },
    getBankByContract : function(entId, logiId) {
      return getBankByContract(entId, logiId);
    },
    getBankTpl : function() {
      return getBankTpl();
    },
    getLogisticsDs : function() {
      return getLogisticsDs();
    },
    getLogisticsTpl : function() {
      return getLogisticsTpl();
    },
    getPeriodPayDate : function() {
      return getPeriodPayDate();
    },
    getEnterpriseDs : function() {
      return getEnterpriseDs();
    },
    getEnterpriseContractDs : function(type) {
      return getEnterpriseContractDs(type);
    },
    getEnterpriseTpl : function() {
      return getEnterpriseTpl();
    },
    getBuyerDs : function() {
      return getBuyerDs();
    },
    getBuyerTpl : function() {
      return getBuyerTpl();
    },
    getSellerDs : function() {
      return getSellerDs();
    },
    getSellerTpl : function() {
      return getSellerTpl();
    },
    getBContractPropertyDs : function() {
      return getBContractPropertyDs();
    },
    getBContractPropertyTpl : function() {
      return getBContractPropertyTpl();
    },
    getLoanNatureDs : function(companyId) {
      return getLoanNatureDs(companyId);
    },
    getLoanNatureTpl : function() {
      return getLoanNatureTpl();
    },
    getGoodsCodeDs : function(flg) {
      return getGoodsCodeDs(flg);
    },
    getGoodsCodeTpl : function() {
      return getGoodsCodeTpl();
    },
    getBankTypeDs : function() {
      return getBankTypeDs();
    },
    getSupplierBlackDs : function() {
      return getSupplierBlackDs();
    },
    getAccountTypeDs : function() {
      return getAccountTypeDs();
    },
    getTofficesDs : function() {
      return getTofficesDs();
    },
    getSupplierEnableDs : function() {
      return getSupplierEnableDs();
    },
    getMaterialDs : function() {
      return getMaterialDs();
    },
    getBankTypeTpl : function() {
      return getBankTypeTpl();
    },
    getRunStatusTbr : function() {
      return getRunStatusTbr();
    },
    getRunLogViewSel : function() {
      return getRunLogViewSel();
    },
    getUsersDs : function() {
      return getUsersDs();
    },
    getHighValueType : function() {
      return getHighValueType();
    },
    getHours : function() {
      return getHours();
    },
    getHoursLocal : function() {
      return getHoursLocal();
    },
    getMins : function() {
      return getMins();
    },
    getMinsLocal : function() {
      return getMinsLocal();
    },
    getAutoRunBefDays : function() {
      return getAutoRunBefDays();
    },
    pctChangeRowColor : function(val) {
      return pctChangeRowColor(val);
    },
    changeRowColor : function(val) {
      return changeRowColor(val);
    },
    getSelect : function() {
      return getSelect();
    },
    getStockDs : function() {
      return getStockDs();
    },
    getActionTypeDs : function() {
      return getActionTypeDs();
    },
    getApportionModeDs : function() {
      return getApportionModeDs();
    },
    getApportionModeTpl : function() {
      return getApportionModeTpl();
    },
    getWindowHeight : function() {
      return getWindowHeight();
    },
    getWindowWidth : function() {
      return getWindowWidth();
    },
    getPrecent : function() {
      return getPrecent();
    },
    asMoney : function(v) {
      v = (Math.round((v - 0) * 100)) / 100;
      v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10))
          ? v + "0"
          : v);
      v = String(v);
      var ps = v.split('.'), whole = ps[0], sub = ps[1] ? '.' + ps[1] : '.00', r = /(\d+)(\d{3})/;
      while (r.test(whole)) {
        whole = whole.replace(r, '$1' + ',' + '$2');
      }
      v = whole + sub;
      // if (v.charAt(0) == '-') {
      // return '-$' + v.substr(1);
      // }
      // return "$" + v;

      return v;
    },
    asInt : function(v) {
      v = (Math.round((v - 0) * 100)) / 100;

      return v;
    },
    // grid 数字显示
    asNum : function num(val) {
      if (val > 0) {
        return '<span style="color:green;">' + val + '</span>';
      } else if (val < 0) {
        return '<span style="color:red;">' + val + '</span>';
      }

      return val;

    },

    getAlldefaultValues : function() {
      return defaultValues();
    },

    // 取系统参数
    // var a = Divo.com.Lib.getDefautlValue("user_Hospital.Info");
    // alert(a.setupValue);
    getDefautlValue : function(setupCode) {
      var data = defaultValues();
      var one = {};
      for (var index = 0; index < data.length; index++) {
        one = data[index];
        if (one.setupCode == setupCode) {
          break;
        }
      }

      return one;
    },

    getSysConfig : function() {
      var sysConfig;

      Ext.Ajax.request({
            url : "common/getsystemconfig",
            scope : this,
            async : false,
            callback : function(o, s, r) {
              var resp = Ext.decode(r.responseText);
              sysConfig = {
                user_name : resp.user_name,
                application_name : resp.application_name,
                vendor : resp.vendor,
                copyright : resp.copyright,
                run_mode : resp.run_mode,
                version : resp.version,
                website : resp.website,
                buildId : resp.buildId,
                module_name : resp.resource.text,
                module_id : resp.resource.resourceId,
                current_user : resp.current_user
              }
            }
          });
      return sysConfig;
    },

    // 参考奖金系统 Divo.bonus.getGroupingHeaderGridMeta
    getGroupingHeaderGridMeta : function(result, rowsResult) {
      var meta = {};
      meta.findColumn = function(name) {
        for (var i = 0; i < this.cms.length; i++) {
          if (this.cms[i].dataIndex === name) {
            return i
          }
        }
        return null
      };
      meta.findMetaIndex = function(name) {
        for (var i = 0; i < this.metas.length; i++) {
          if (this.metas[i].name === name) {
            return i
          }
        }
        return null
      };
      if (!result) {
        meta.recordDef = Ext.data.Record.create([{
              name : ""
            }]);
        meta.columnModel = new Ext.grid.ColumnModel([{
              header : ""
            }]);
        return meta
      }
      var rs = [], cms = [], fs = [], metas = [], rows = [], row = [];

      for (var i = 0; i < result.length; i++) {
        metas.push({
              name : result[i].dataIndex,
              header : result[i].header
            });
        rs.push({
              name : result[i].dataIndex
            });
        if (result[i].header) {
          cms.push({
                header : result[i].header,
                width : result[i].width,
                hidden : result[i].hidden,
                sortable : result[i].sortable,
                resizable : result[i].resizable,
                align : result[i].align,
                dataIndex : result[i].dataIndex
              });

        }
      }

      if (rowsResult) {
        for (var i = 0; i < rowsResult.length; i++) {
          rows.push({
                header : rowsResult[i].header,
                colspan : rowsResult[i].colspan,
                align : rowsResult[i].align,
                width : rowsResult[i].width
              });
        }
      }

      row.push(rows);

      meta.recordDef = Ext.data.Record.create(rs);
      meta.columnModel = new Ext.grid.ColumnModel(cms);

      meta.columnModel.rows = row;

      meta.columnModel.defaultSortable = false;
      meta.rs = rs;
      meta.cms = cms;
      meta.metas = metas;
      return meta
    },

    getSearchIcon : function() {
      return "resources/img/filter.gif";
    },

    getCollapseallIcon : function() {
      return "resources/img/collapseall.gif";
    },

    getExpandallIcon : function() {
      return "resources/img/expandall.gif";
    },

    getNewIcon : function() {
      return "resources/img/g_rec_new.png";
    },

    getEditIcon : function() {
      return "resources/img/g_rec_upd.png";
    },

    getPublishIcon : function() {
      return "resources/img/fam.icons/application_go.png";
    },

    getDelIcon : function() {
      return "resources/img/g_rec_del.png";
    },
    getExceptionDs : function() {
      return getExceptionDs();
    },
    getExceptionTpl : function() {
      return getExceptionTpl();
    },
    getStaticDateDs : function(data) {
      return getStaticDateDs(data);
    },
    /**
     * 不显示网格列标题
     */
    hideGridHeader : function(grid) {
      grid.getView().el.select('.x-grid3-header').setStyle('display', 'none');
    }

  }
}();

Divo.com.Lib.init();
